import time
from decimal import Decimal
import numpy as np
from flask import jsonify
from redis import Redis
import math
client = Redis(host='10.86.184.170', port=6379, decode_responses=True)
value = [0, 0, 0, 0]
t=[0]

#获取当前时间
def get_time():
    time_str = time.strftime("%Y{}%m{}%d{} %X")
    return time_str.format("年","月","日")



def get_c1_data():

    OrderTotal = client.get("Total")
    PriceTotal = client.get("TotalOrders")
    RecTotal = client.zcard("NumOfRecipent")
    Speed = int(PriceTotal)-t[0]
    t[0] = int(PriceTotal)
    value[0] = int(Speed)
    value[1] = PriceTotal
    value[2] = OrderTotal
    value[3] = RecTotal
    return value

def get_l2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('Top10BookType', 0, 9, withscores=True)
    return type

def get_l1_data():
    data = client.zrevrange('price', 0, -1, withscores=True)

    return data

def get_r2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('Top10Press', 0, 9, withscores=True)
    return type

def get_r1_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('Top10Books', 0, 9, withscores=True)
    return type

def get_c2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    # province = client.get("OrderTotal")
    province = client.zrange('receiveplace', 0, -1, withscores=True, desc=True)
    # print(province)
    return province


if __name__ == '__main__':
    print(get_l1_data())
    client.close()